package time

import (
	"strconv"
	"time"
)

// @param last The limit of last minutes.
// @param setp The gap of per timestamp.
// @param offset The start time offset.
// @param isAsc Sort timestamp by ASC.
// @param current Is include current time.
func LastMinutesTimestampString(last int, step int64, offset int64, isAsc bool, current bool) (minutes []string) {
	theTimeStr := time.Now().Format("2006-01-02 15:04  MST")
	theTimeMinute, _ := time.Parse("2006-01-02 15:04  MST", theTimeStr)
	minute := theTimeMinute.Unix() - offset // set offset.

	// include current
	fix := 1
	if current {
		fix = 0
	}

	minutes = make([]string, last)
	if isAsc {
		minute = minute - int64(last-fix)*60*step
		for i := 0; i < last; i++ {
			minutes[i] = strconv.FormatInt((minute + int64(i)*60*step), 10)
		}
	} else {
		for i := 0; i < last; i++ {
			minutes[i] = strconv.FormatInt((minute - int64(i)*60*step), 10)
		}
	}

	return
}
